//
//  UIImage+Extension.m
//  AmountBody
//
//  Created by Qiu Jishuai on 2018/1/25.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

#import "UIImage+Extension.h"

@implementation UIImage (Extension)
- (UIImage *)stretchImageWithInsetsTop: (CGFloat)top left: (CGFloat)left bottom: (CGFloat)bottom right: (CGFloat)right {
    UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
    return [self resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
}
- (instancetype)alwaysOriginalImage {
    return [self imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}

+ (instancetype)imageByColor:(UIColor *)color
                        size: (CGSize)size
                cornerRadius:(CGFloat)radius
                 borderWidth:(CGFloat)borderWidth
                 borderColor:(UIColor *)borderColor
                 stretch: (BOOL)stretch {
    if (CGSizeEqualToSize(size, CGSizeZero)) {
        size = CGSizeMake(1.0f, 1.0f);
    }
    UIImage *image = [UIImage imageWithColor:color size: size];
    image = [image imageByRoundCornerRadius:radius borderWidth:borderWidth borderColor:borderColor];
    if (stretch) {
    image = [image stretchImageWithInsetsTop:radius left:radius bottom:radius right:radius];
    }
    return image;
}

@end
